﻿using System.Drawing;
using System.Windows.Forms;

using AutoduelClient.GameClient.Player;
using AutoduelClient.GameClient.Locations;

namespace AutoduelClient.GameUI
{
    public partial class LocationOptionsDialog : Form
    {
        private Location location;

        #region Constructors (2)
		public LocationOptionsDialog()
        {
            InitializeComponent();
        }

		public LocationOptionsDialog(Location location)
        {
            InitializeComponent();

            this.location = location;

            foreach (MenuChoice choice in location.ProvideMenuChoices())
            {
                menuChoices.Items.Add(choice);
            }
        }
		#endregion

		#region Event Handlers (2)

		private void OptionsDialog_Load(object sender, System.EventArgs e)
        {
            this.Location = new Point(this.Owner.Location.X + this.Owner.Width / 2 - this.Width / 2, 
                this.Owner.Location.Y + this.Owner.Height / 2 - this.Height / 2);
        }

		private void menuChoices_DoubleClick(object sender, System.EventArgs e)
        {
            if (menuChoices.SelectedIndex > -1)
            {
                MenuChoiceDisplayer menuChoiceDisplayer = new MenuChoiceDisplayer((MenuChoice)menuChoices.SelectedItem);

                // need to check for IsDisposed because some menu choices do not use a menuChoiceDisplayer
                // so it is never full initialized
                if (!menuChoiceDisplayer.IsDisposed)
                {
                    this.Enabled = false;
                    menuChoiceDisplayer.Show(this);
                }

                this.DialogResult = DialogResult.OK;
                //this.Dispose();
            }
        }

		#endregion

        private void OptionsDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Owner.Enabled = true;
            this.location.Exit();
        }
    }
}
